import requests


class EmpManageApi(object):
    #添加员工
    def add_emp(self, req_head, req_data):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head, json=req_data)
        return resp
    #查询员工
    def query_emp(self,emp_id,req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,headers=req_head)
        return resp
    #修改员工
    def modify_emp(self,emp_id,req_head, req_data):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,
                            headers=req_head,json=req_data)
        return resp
    #删除员工
    def del_emp(self,emp_id,req_head):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/"+emp_id,headers=req_head)
        return resp


if __name__ == '__main__':
    emp = EmpManageApi()
    req_head = {"Authorization": "a38d0469-1c8f-4ede-8a00-7a16b8ee49d6"}
    req_data = {"username": "jack123","mobile": "13858034546","workNumber": "666"}
    resp1=emp.add_emp(req_head, req_data)
    print("添加员工：",resp1.json())

    emp_id="1570678767465017344"
    resp2=emp.query_emp(emp_id,req_head)
    print("查询员工：",resp2.json())

    modify_req_data={"username":"小猪佩奇"}
    resp3=emp.modify_emp(emp_id,req_head,modify_req_data)
    print("修改员工：",resp3.json())

    resp4=emp.del_emp(emp_id,req_head)
    print("删除员工：", resp4.json())
